package com.zhike.util;

import java.util.Map;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;

public class Jdpush {
	 // 设置好账号的app_key和masterSecret是必须的
	private final static String appKey = "2bdc3dba52cd5ccc28c1ff0c";
	 
    private final static String masterSecret = "e949e6b3e34bd5d739cdbb9d";
    //创建JPushClient
    private static JPushClient jpushClient = new JPushClient(masterSecret,appKey);
	
	
	 //极光推送
	   //Map<String, String> parm是我自己传过来的参数,可以自定义参数
	   public static void jpushAlias(Map<String, String> parm) {
	       //推送的关键,构造一个payload 
	       PushPayload payload = PushPayload.newBuilder()
	            .setPlatform(Platform.all())//指定所有平台的用户
	            .setAudience(Audience.alias(parm.get("alias")))//别名用户
	            .setNotification(Notification.android(parm.get("msg"), parm.get("title"), parm))
	            //发送内容,这里不要盲目复制粘贴,这里是我从controller层中拿过来的参数)
	            .setOptions(Options.newBuilder().setApnsProduction(false).build())
	            //这里是指定开发环境,不用设置也没关系
	            .setMessage(Message.content(parm.get("msg")))//自定义信息
	            .build();

	       try {
	            PushResult pu = jpushClient.sendPush(payload);

	        } catch (APIConnectionException e) {
	            e.printStackTrace();
	        } catch (APIRequestException e) {
	            e.printStackTrace();
	        }    
	   }
	   

		 //极光推送
		   //Map<String, String> parm是我自己传过来的参数,可以自定义参数
		   public static void jpushAll(Map<String, String> parm) {
		       //推送的关键,构造一个payload 
		       PushPayload payload = PushPayload.newBuilder()
		            .setPlatform(Platform.all())//指定所有平台的用户
		            .setAudience(Audience.all())//别名用户
		            .setNotification(Notification.android(parm.get("msg"), parm.get("title"), parm))
		            //发送内容,这里不要盲目复制粘贴,这里是我从controller层中拿过来的参数)
		            .setOptions(Options.newBuilder().setApnsProduction(false).build())
		            //这里是指定开发环境,不用设置也没关系
		            .setMessage(Message.content(parm.get("msg")))//自定义信息
		            .build();

		       try {
		            PushResult pu = jpushClient.sendPush(payload);

		        } catch (APIConnectionException e) {
		            e.printStackTrace();
		        } catch (APIRequestException e) {
		            e.printStackTrace();
		        }    
		   }

	   

}
